﻿using ZFramework.Runtime;
using GameWorldOwner = ZFramework.Runtime.Fsm<ZFramework.Runtime.IGameWorldManager>;
namespace ZGame
{
    public class GameWorldPreLoad : GameWorldBase
    {
        public override void OnEnter(GameWorldOwner gameWorldOwner)
        {
            base.OnEnter(gameWorldOwner);
            Log.Error("开始  GameWorldPreset");
            PreLoadResources();
        }

        public override void OnUpdate(GameWorldOwner gameWorldOwner, float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(gameWorldOwner, elapseSeconds, realElapseSeconds);
            if (!GameEntry.fguiUIPackageMgr.IsPreloadReady)
                return;

            SetInfos();
            
            ChangeState<GameWorldLogin>(gameWorldOwner);
        }

        void PreLoadResources()
        {
            LoadGlobalConfig();
            LoadUIPackageInfo();
        }

        void LoadUIPackageInfo()
        {
            GameEntry.fguiUIPackageMgr.PreLoad();
        }

        void LoadGlobalConfig()
        {
            //TODO:加载全局配置表   
        }

        void SetInfos()
        {
            SetUIGroups();

            InitUIPackages();
        }

        void InitUIPackages()
        {
            GameEntry.fguiUIPackageMgr.InitUIPackages();
        }

        void SetUIGroups()
        {
            GameEntry.uiMgr.AddUIGroup<FGuiUIGroupHelper>("BackGround", 1);
            GameEntry.uiMgr.AddUIGroup<FGuiUIGroupHelper>("Normal", 2);
            GameEntry.uiMgr.AddUIGroup<FGuiUIGroupHelper>("Top", 3);
        }
    }
}